package org.example.service.impl;

import io.jsonwebtoken.Claims;
import org.example.mapper.UserPermissionMapper;
import org.example.service.PermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PermissionServiceImpl implements PermissionService {
    public final Integer CHANGE_CLASS_ACCOUNT_PERMISSION = 1;

    @Autowired
    private UserPermissionMapper userPermissionMapper;

    //query:查看的权限
    @Override
    public boolean permissionInQueryClassAccountTable(Claims claims, String classCode) {
        return claims.get("classCode").equals(classCode);
    }
    //change:增删改的权限
    @Override
    public boolean permissionInChangeClassAccountTable(Claims claims) {
        Integer userId = Integer.parseInt(claims.get("id").toString());
        List<Integer> userIds = userPermissionMapper.searchUserIdsByPermissionId(CHANGE_CLASS_ACCOUNT_PERMISSION);
        return userIds.contains(userId);
    }
}
